package bb.lanxing.util.img;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import androidx.fragment.app.Fragment;
import java.util.ArrayList;
import java.util.Iterator;

public class ImageChooserUtil {
    public static final String EXTRA_MAX_SELECTABLE = "multi-image-max_selectable";
    public static final String EXTRA_RETURN_PICTURES = "multi-image-data";
    public static final String EXTRA_SELECTED_LIST = "multi-image-selected_list";

    public static void startChooser(Activity activity, int i, ArrayList<String> arrayList, int i2) {
        Intent intent = new Intent(activity, ImageChooserActivity.class);
        intent.putExtra(EXTRA_MAX_SELECTABLE, i);
        intent.putStringArrayListExtra(EXTRA_SELECTED_LIST, arrayList);
        activity.startActivityForResult(intent, i2);
    }

    public static void startChooser(Fragment fragment, int maxSelectable, ArrayList<String> arrayList, int requestCode) {
        Intent intent = new Intent(fragment.getActivity(), ImageChooserActivity.class);
        intent.putExtra(EXTRA_MAX_SELECTABLE, maxSelectable);
        intent.putStringArrayListExtra(EXTRA_SELECTED_LIST, arrayList);
        fragment.startActivityForResult(intent, requestCode);
    }

    public static ArrayList<String> getSelectedImagePath(Intent intent) {
        ArrayList<LocalFile> selectedImage = getSelectedImage(intent);
        ArrayList<String> arrayList = new ArrayList<>(selectedImage.size());
        Iterator<LocalFile> it = selectedImage.iterator();
        while (it.hasNext()) {
            arrayList.add(it.next().getPath());
        }
        return arrayList;
    }

    public static ArrayList<Uri> getSelectedImageUri(Intent intent) {
        ArrayList<LocalFile> selectedImage = getSelectedImage(intent);
        ArrayList<Uri> arrayList = new ArrayList<>(selectedImage.size());
        Iterator<LocalFile> it = selectedImage.iterator();
        while (it.hasNext()) {
            arrayList.add(it.next().getUri());
        }
        return arrayList;
    }

    public static ArrayList<LocalFile> getSelectedImage(Intent intent) {
        return intent.getParcelableArrayListExtra(EXTRA_RETURN_PICTURES);
    }
}
